/// 此文件定义一些常用类型供xcb模块使用
pub const xcb = @cImport({
    @cInclude("X11/keysym.h");
    @cInclude("sys/param.h");
    @cInclude("xcb/xcb.h");
    @cInclude("xcb/xcb_aux.h");
    @cInclude("xcb/xcb_errors.h");
    @cInclude("xcb/xcb_keysyms.h");
    @cInclude("xcb/xkb.h");
    @cInclude("xcb/xcb_icccm.h");
    @cInclude("xcb/xcb_event.h");
    @cInclude("xcb/xcb_ewmh.h");
});

pub const WM_PROTOCOLS = "WM_PROTOCOLS";
pub const WM_DELETE_WINDOW = "WM_DELETE_WINDOW";
// 边框宽度
pub const BORDER_WIDTH: u16 = 3;
// 边框未选中颜色
pub const BORDER_COLOR_UNSELECTED: u32 = 0xff0000;
// 边框选中颜色
pub const BORDER_COLOR_SELECTED: u32 = 0xff0000;
// 窗口帧背景色
pub const BG_COLOR: u32 = 0xeffaf0;
// 标题栏高度
pub const TITLE_HEIGHT: u16 = 10;

// 以下是可能的掩码定义。请注意，这些定义可能在不同的 X 实现和键盘型号之间有所不同。
//     XCB_MOD_MASK_1       -> Alt_L Alt_R Meta_L
//     XCB_MOD_MASK_2       -> Num_Lock
//     XCB_MOD_MASK_3       -> ISO_Level3_Shift
//     XCB_MOD_MASK_4       -> Super_L Super_R SuperL Hyper_L
//     XCB_MOD_MASK_5       -> ISO_Level5_Shifta
//     XCB_MOD_MASK_SHIFT
//     XCB_MOD_MASK_CONTROL
//     XCB_MOD_MASK_LOCK
//     XCB_MOD_MASK_ANY
pub const Key = struct {
    mod: c_uint,
    keysym: xcb.xcb_keysym_t,
    func: *const fn (argv: [*:null]const ?[*:0]const u8) void,
    com: [*:null]const ?[*:0]const u8,
};

pub const Position = struct {
    x: i32,
    y: i32,
};

pub const Size = struct {
    width: u32,
    height: u32,
};

pub const Vector2D = struct {
    x: i32,
    y: i32,
};

pub const WmErr = error{
    NotConnect,
    CannotCreateErrContext,
    CannotGetWmProtocols,
    CannotGetWmDeleteWindow,
    NoDefaultScreen,
    CannotSubstructureRedirect,
    CannotGrabServer,
    ErrorIsNull,
    CannotGetRootWindow,
    CannotQueryWindowTree,
    CannotUngrabServer,
    AlreadyFramed,
    CannotGetWindowAttributes,
    CannotGetGeometry,
    CantnotCreateFrame,
    CannotSubstructureRedirectFrame,
    CannotSaveClientSet,
    CannotMapFrame,
    CannotMapWindow,
    CannotPairedFrame,
    CannotGrabButton,
    CannotGetKeycodeBySym,
    CannotGrabKey,
    CannotUnmapFrame,
    CannotUnmapWindow,
    CannotReparentFrameWindow,
    CannotReparentRootWindow,
    CannotDeleteClientSet,
    CannotDestroyFrame,
    CannotRemoveWindowMap,
    AllocatedMemoryFail,
    CannotConfigureWindow,
    NotFoundFrameFromMap,
    CannotRaiseWindow,
    CannotMoveWindow,
    CannotResizeWindow,
    CannotSendCloseMsg,
    CannotKillWindow,
    NoSuchAtom,
    CannotGetXcbError,
    EventElemIsNull,
    CannotAllocMemory,
    CannotCreateThread,
    PipeBroken,
    CannotFlushConn,
    CannotSwitchWindow,
    ExistKey,
    Unkown,
};

pub fn asText(err: WmErr) []const u8 {
    switch (err) {
        error.NotConnect => return "Cannot connect to server",
        error.CannotCreateErrContext => return "Cannot create errors for xcb context",
        error.CannotGetWmProtocols => return "Cannot get WM_PROTOCOLS from connection",
        error.CannotGetWmDeleteWindow => return "Cannot get WM_DELETE_WINDOW from connection",
        error.NoDefaultScreen => return "No default screen found",
        error.CannotSubstructureRedirect => return "Cannot set the window substructure redirect flag",
        error.CannotGrabServer => return "Cannot grab window server",
        else => return "Unkown error",
    }
}
